package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class AddOperation implements IOperation{
    @Override
    public void work(BookList booklist) {
        System.out.println("新增图书");
        System.out.println("请输入你要新增的图书：");
        Scanner sc=new Scanner(System.in);
        String name=sc.nextLine();
        int currentSize= booklist.getUsedSize();
        for(int i=0;i< currentSize;i++){
            Book book=booklist.getBooks(i);
            if(book.getName().equals(name)){
                System.out.println("该书已经存在，不可新增");
                System.out.println(book);
                return;
            }
        }
        System.out.println("请输入你要新增的图书作者：");
        String author=sc.nextLine();
        System.out.println("请输入你要新增的图书价格：");
        int price=sc.nextInt();
        sc.nextLine();//吃掉回车
        System.out.println("请输入你要新增的图书类型：");
        String type=sc.nextLine();
        Book book=new Book(name,author,price,type);
        booklist.setBooks(currentSize,book);
        booklist.setUsedSize(currentSize+1);
        System.out.println("新增成功！");
    }
}
